package cj.web.marriage.dao;
/*
 *  
 *  
*/
import java.util.List;

import net.paoding.rose.jade.annotation.DAO;
import net.paoding.rose.jade.annotation.SQL;
import net.paoding.rose.jade.annotation.SQLParam;
import cj.web.marriage.domain.MarriageReg;

/**
 * 
 * @author 
 *
 */
@DAO
public interface MarriageRegDAO{
	
	@SQL("SELECT * FROM MarriageReg WHERE type!=0 and addressId in (:li) #if(:t.link!=''){ AND link like '%##(:t.link)%'} #if(:t.man!=''){ and (man like '%##(:t.man)%' or manCard like '%##(:t.manCard)%')}  #if(:t.woman!=''){ and ( woman like '%##(:t.woman)%' or womanCard like '%##(:t.womanCard)%' )} #if(:t.status!=-1){ AND status = :t.status } #if(:t.type!=-1){ AND type = :t.type } ORDER BY type ASC,createAt DESC LIMIT :t.start,:t.length ")
    List<MarriageReg> query(@SQLParam("t") MarriageReg marriageReg,@SQLParam("li") List<Integer> addressIds);
	
	@SQL("SELECT count(1) FROM MarriageReg WHERE type!=0 and addressId in (:li) #if(:t.link!=''){ AND link like '%##(:t.link)%'} #if(:t.man!=''){ and ( man like '%##(:t.man)%' or manCard like '%##(:t.manCard)%')}  #if(:t.woman!=''){ and ( woman like '%##(:t.woman)%' or womanCard like '%##(:t.womanCard)%' )} #if(:t.status!=-1){ AND status = :t.status } #if(:t.type!=-1){ AND type = :t.type }")
	int querysize(@SQLParam("t") MarriageReg marriageReg,@SQLParam("li") List<Integer> addressIds);
    
    @SQL("select * from MarriageReg where id=:1")
    MarriageReg queryById(String id);
    
    @SQL("INSERT INTO MarriageReg (man,manCard,woman,womanCard,regTime,addressId,link,status,createAt,type,code,setMealId,memo,manType,womanType) VALUES (:t.man,:t.manCard,:t.woman,:t.womanCard,:t.regTime,:t.addressId,:t.link,:t.status,now(),:t.type,:t.code,:t.setMealId,:t.memo,:t.manType,:t.womanType) ")
    void create(@SQLParam("t") MarriageReg marriageReg);
	
	@SQL("UPDATE MarriageReg SET man=:t.man,manCard=:t.manCard,woman=:t.woman,womanCard=:t.womanCard, addressId=:t.addressId,status=:t.status, link=:t.link, regTime=:t.regTime, type=:t.type, code=:t.code, setMealId=:t.setMealId,memo=:t.memo,manType=:t.manType,womanType=:t.womanType WHERE id=:t.id ")
    void update(@SQLParam("t") MarriageReg marriageReg);

	@SQL("UPDATE MarriageReg SET status=:t.status,memo='' WHERE id=:t.id")
	void finish(@SQLParam("t") MarriageReg marriageReg);
	
	@SQL("UPDATE MarriageReg SET status=:t.status,memo=:t.memo WHERE id=:t.id")
	void refuse(@SQLParam("t") MarriageReg marriageReg);
    
	@SQL("SELECT count(1) FROM MarriageReg WHERE manCard IN (:t.manCard, :t.womanCard) AND type=:t.type AND status=1 AND regTime > NOW()")
	int repeatMan(@SQLParam("t") MarriageReg marriageReg);
	
	@SQL("SELECT count(1) FROM MarriageReg WHERE womanCard IN (:t.manCard, :t.womanCard) AND type=:t.type AND status=1 AND regTime > NOW()")
	int repeatWoman(@SQLParam("t") MarriageReg marriageReg);

	//颁证仪式列表
	@SQL("SELECT * FROM MarriageReg WHERE type=0 and addressId in (:li) #if(:t.man!=''){ AND man like '%##(:t.man)%'} #if(:t.status!=-1){ AND status = :t.status } ORDER BY createAt DESC LIMIT :t.start,:t.length ")
    List<MarriageReg> queryCeremony(@SQLParam("t") MarriageReg marriageReg,@SQLParam("li") List<Integer> addressIds);
	
	@SQL("SELECT count(*) FROM MarriageReg WHERE type=0 and addressId in (:li) #if(:t.man!=''){ AND man like '%##(:t.man)%'} #if(:t.status!=-1){ AND status = :t.status }")
	int queryCeremonySize(@SQLParam("t") MarriageReg marriageReg,@SQLParam("li") List<Integer> addressIds);
	
	//颁证仪式预约是否重复
	@SQL("SELECT count(1) FROM MarriageReg WHERE man=:t.man AND link=:t.link AND type=:t.type AND status=1 AND regTime > now()")
	int repeatCeremony(@SQLParam("t")MarriageReg marriageReg);
	
	//颁证仪式预约更新
	@SQL("UPDATE MarriageReg SET man=:t.man, addressId=:t.addressId,status=:t.status, link=:t.link, regTime=:t.regTime, code=:t.code, setMealId=:t.setMealId,memo=:t.memo,manType=:t.manType,womanType=:t.womanType WHERE id=:t.id")
    void updateCeremony(@SQLParam("t") MarriageReg marriageReg);
    
    
}